home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 February / SGI IRIX 6.5 Complementary Applications 2004 February.iso / dist / cde.idb / usr / dt / share / examples / dtterm / term.c.z / term.c
Encoding:
C/C++ Source or Header  |  2003-11-18  |  4.9 KB  |  165 lines

  1. /*
  2.  * term.c
  3.  *
  4.  * Copyright 2000, Silicon Graphics, Inc.
  5.  * ALL RIGHTS RESERVED
  6.  * 
  7.  * UNPUBLISHED -- Rights reserved under the copyright laws of the United
  8.  * States.   Use of a copyright notice is precautionary only and does not
  9.  * imply publication or disclosure.
  10.  *
  11.  * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  12.  * Use, duplication or disclosure by the Government is subject to restrictions
  13.  * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  14.  * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  15.  * in similar or successor clauses in the FAR, or the DOD or NASA FAR
  16.  * Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  17.  * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  18.  *
  19.  * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  20.  * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  21.  * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  22.  * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  23.  * GRAPHICS, INC.
  24.  */
  25. /* $XConsortium: term.c /main/cde1_maint/1 1995/07/17 16:45:08 drk $ */
  26. /*
  27.  * (c) Copyright 1993, 1994 Hewlett-Packard Company    
  28.  * (c) Copyright 1993, 1994 International Business Machines Corp.
  29.  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  30.  * (c) Copyright 1993, 1994 Novell, Inc.
  31.  */
  32.  
  33.  
  34. /*
  35.  * term.c
  36.  *
  37.  * Example code for DtTerm widget
  38.  *
  39.  * Create a terminal widget running a shell and provide
  40.  * push button shortcuts for shell commands. Regular shell
  41.  * commands can be entered also.
  42.  */
  43.  
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <unistd.h>
  47. #include <Xm/MessageB.h>
  48. #include <Xm/Frame.h>
  49. #include <Xm/Label.h>
  50. #include <Xm/PushB.h>
  51. #include <Dt/Term.h>
  52.  
  53. static Widget toplevel;
  54.  
  55. static void CreateTerm(Widget, char *);
  56. static void SendCommandCb(Widget, XtPointer, XtPointer);
  57. static void AddCommandButton(Widget, char *, char *);
  58.  
  59. main(int argc, char **argv)
  60. {
  61.     XtAppContext appContext;
  62.     Arg args[20];
  63.     int n;
  64.     XmString labelString;
  65.  
  66.     Widget mainWindow, termContainer, termTitle;
  67.     
  68.     /* Initialize DtTerm widget library */
  69.  
  70.     DtTermInitialize();
  71.  
  72.     toplevel = XtAppInitialize(&appContext, "Term", NULL, 0, &argc, argv,
  73.                 NULL, NULL, 0);
  74.  
  75.     n = 0;
  76.     XtSetArg(args[n], XmNdialogType, XmDIALOG_TEMPLATE); n++;
  77.     mainWindow = XmCreateMessageBox(toplevel, "mainWindow", args, n);
  78.     XtManageChild(mainWindow);
  79.  
  80.     n = 0;
  81.     XtSetArg(args[n], XmNmarginWidth, 10); n++;
  82.     XtSetArg(args[n], XmNmarginHeight, 10); n++;
  83.     termContainer = XmCreateFrame(mainWindow, "termContainer", args, n);
  84.     XtManageChild(termContainer);
  85.  
  86.     labelString = XmStringCreateLocalized("DtTerm with date and time shortcuts");
  87.     n = 0;
  88.     XtSetArg(args[n], XmNchildType, XmFRAME_TITLE_CHILD); n++;
  89.     XtSetArg(args[n], XmNlabelString, labelString); n++;
  90.     termTitle = XmCreateLabel(termContainer, "termTitle", args, n);
  91.     XtManageChild(termTitle);
  92.     XmStringFree(labelString);
  93.  
  94.     /* Create the terminal widget */
  95.  
  96.     CreateTerm(termContainer, "/bin/sh");
  97.  
  98.     /* Add shortcut buttons to the message box */
  99.  
  100.     AddCommandButton(mainWindow, "Today", "date\n");
  101.     AddCommandButton(mainWindow, "Month", "cal\n");
  102.     AddCommandButton(mainWindow, "1994", "clear;cal 1994\n");
  103.     AddCommandButton(mainWindow, "1995", "clear;cal 1995\n");
  104.     AddCommandButton(mainWindow, "1996", "clear;cal 1996\n");
  105.     AddCommandButton(mainWindow, "1997", "clear;cal 1997\n");
  106.     AddCommandButton(mainWindow, "1998", "clear;cal 1998\n");
  107.     AddCommandButton(mainWindow, "1999", "clear;cal 1999\n");
  108.     AddCommandButton(mainWindow, "2000", "clear;cal 2000\n");
  109.  
  110.     XtRealizeWidget(toplevel);
  111.     XtAppMainLoop(appContext);
  112. }
  113.  
  114.  
  115. /*
  116.  * Create a DtTerm
  117.  */
  118.  
  119. static void CreateTerm(Widget parent, char *cmd)
  120. {
  121.     Widget term;
  122.     Arg args[20];
  123.     int n;
  124.     
  125.     /*
  126.      * Create a DtTerm widget.
  127.      * Pass the command to execute.
  128.      * Configure the window to fit a calendar year.
  129.      */
  130.  
  131.     n = 0;
  132.     XtSetArg(args[n], DtNsubprocessCmd, cmd); n++;
  133.     XtSetArg(args[n], DtNrows, 46); n++;
  134.     XtSetArg(args[n], DtNcolumns, 80); n++;
  135.     term = DtCreateTerm(parent, "term", args, n);
  136.     XtManageChild(term);
  137. }
  138.  
  139. static void AddCommandButton(Widget parent, char *label, char *cmd)
  140. {
  141.     XmString labelString;
  142.     Arg args[1];
  143.     Widget button;
  144.  
  145.     /* Create a pushbutton which will send a command to the terminal */
  146.  
  147.     labelString = XmStringCreateLocalized(label);
  148.     XtSetArg(args[0], XmNlabelString, labelString);
  149.     button = XmCreatePushButton(parent, label, args, 1);
  150.     XtManageChild(button);
  151.     XmStringFree(labelString);
  152.     XtAddCallback(button, XmNactivateCallback, SendCommandCb, (XtPointer)cmd);
  153. }
  154.  
  155. static void SendCommandCb(Widget w, XtPointer cd, XtPointer cb)
  156. {
  157.     Widget term = XtNameToWidget(toplevel, "*term");
  158.     unsigned char *cmd = (unsigned char*)cd;
  159.  
  160.     /* send the pushbutton command to the terminal widget */
  161.  
  162.     DtTermSubprocSend(term, cmd, strlen((char*)cmd));
  163. }
  164.  
  165.